//
// Created by 鲲鹏 on 24-6-19.
// 头插法:链表插入
//

#include <iostream>

using namespace std;

struct Node{
    int data;
    Node * next;
};

Node * head = nullptr;

int main(){
    int x;
    while (cin>>x){
        if(x==0)break;
        Node * p = new Node;
        p->data = x;
        p->next = head; // 头插法,head指针一开始指向空,
        head = p;
    }

    for(Node * p = head;p;p = p->next){
        cout<<p->data<<" ";
    }
    return 0;
}
